#ifndef WULC_DILITHIUM_POLY_H_
#define WULC_DILITHIUM_POLY_H_

#include <stdint.h>

#include "params.h"

typedef struct {
    int32_t coeffs[N];
} poly;

/*============================================================================*/
/* Macro definitions                                                          */
/*============================================================================*/

#define poly_reduce DILITHIUM_NAMESPACE(_poly_reduce)
#define poly_caddq DILITHIUM_NAMESPACE(_poly_caddq)
#define poly_freeze DILITHIUM_NAMESPACE(_poly_freeze)

#define poly_add DILITHIUM_NAMESPACE(_poly_add)
#define poly_sub DILITHIUM_NAMESPACE(_poly_sub)
#define poly_shiftl DILITHIUM_NAMESPACE(_poly_shiftl)

#define poly_ntt DILITHIUM_NAMESPACE(_poly_ntt)
#define poly_invntt_tomont DILITHIUM_NAMESPACE(_poly_invntt_tomont)
#define poly_pointwise_montgomery DILITHIUM_NAMESPACE(_poly_pointwise_montgomery)

#define poly_power2round DILITHIUM_NAMESPACE(_poly_power2round)
#define poly_decompose DILITHIUM_NAMESPACE(_poly_decompose)
#define poly_make_hint DILITHIUM_NAMESPACE(_poly_make_hint)
#define poly_use_hint DILITHIUM_NAMESPACE(_poly_use_hint)

#define poly_chknorm DILITHIUM_NAMESPACE(_poly_chknorm)
#define poly_uniform DILITHIUM_NAMESPACE(_poly_uniform)
#define poly_uniform_eta DILITHIUM_NAMESPACE(_poly_uniform_eta)
#define poly_uniform_gamma1 DILITHIUM_NAMESPACE(_poly_uniform_gamma1)
#define poly_challenge DILITHIUM_NAMESPACE(_poly_challenge)

#define polyeta_pack DILITHIUM_NAMESPACE(_polyeta_pack)
#define polyeta_unpack DILITHIUM_NAMESPACE(_polyeta_unpack)

#define polyt1_pack DILITHIUM_NAMESPACE(_polyt1_pack)
#define polyt1_unpack DILITHIUM_NAMESPACE(_polyt1_unpack)

#define polyt0_pack DILITHIUM_NAMESPACE(_polyt0_pack)
#define polyt0_unpack DILITHIUM_NAMESPACE(_polyt0_unpack)

#define polyz_pack DILITHIUM_NAMESPACE(_polyz_pack)
#define polyz_unpack DILITHIUM_NAMESPACE(_polyz_unpack)

#define polyw1_pack DILITHIUM_NAMESPACE(_polyw1_pack)

/*============================================================================*/
/* Function definitions                                                        */
/*============================================================================*/

#ifdef __cplusplus
extern "C"
{ /* start of __cplusplus */
#endif

void poly_reduce(poly *a);
void poly_caddq(poly *a);
void poly_freeze(poly *a);

void poly_add(poly *c, const poly *a, const poly *b);
void poly_sub(poly *c, const poly *a, const poly *b);
void poly_shiftl(poly *a);

void poly_ntt(poly *a);
void poly_invntt_tomont(poly *a);
void poly_pointwise_montgomery(poly *c, const poly *a, const poly *b);

void poly_power2round(poly *a1, poly *a0, const poly *a);
void poly_decompose(poly *a1, poly *a0, const poly *a);
unsigned int poly_make_hint(poly *h, const poly *a0, const poly *a1);
void poly_use_hint(poly *b, const poly *a, const poly *h);

int poly_chknorm(const poly *a, int32_t B);
void poly_uniform(poly *a,
                  const uint8_t seed[SEEDBYTES],
                  uint16_t nonce);
void poly_uniform_eta(poly *a,
                      const uint8_t seed[SEEDBYTES],
                      uint16_t nonce);
void poly_uniform_gamma1(poly *a,
                         const uint8_t seed[CRHBYTES],
                         uint16_t nonce);
void poly_challenge(poly *c, const uint8_t seed[SEEDBYTES]);

void polyeta_pack(uint8_t *r, const poly *a);
void polyeta_unpack(poly *r, const uint8_t *a);

void polyt1_pack(uint8_t *r, const poly *a);
void polyt1_unpack(poly *r, const uint8_t *a);

void polyt0_pack(uint8_t *r, const poly *a);
void polyt0_unpack(poly *r, const uint8_t *a);

void polyz_pack(uint8_t *r, const poly *a);
void polyz_unpack(poly *r, const uint8_t *a);

void polyw1_pack(uint8_t *r, const poly *a);


#ifdef __cplusplus
} /* end of __cplusplus */
#endif

#endif //WULC_DILITHIUM_POLY_H_
